/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ACCOUNT_RECORD.java
 *
 * Created on Oct 3, 2010, 11:10:42 PM
 */

package COMIC_BOOK_STORE;

import java.awt.Component;
import java.sql.*;
import java.text.DecimalFormat;
import java.util.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

/**
 *
 * @author Alexander
 */
public class ACCOUNT_RECORD extends javax.swing.JFrame {

    Statement stat;
    PreparedStatement stmt;
    Connection con;
    ResultSet rset;
    double revenue, expenditure;


    @Override
    public void setLocationRelativeTo(Component c) {
        super.setLocationRelativeTo(c);
    }


    private String url = "jdbc:oracle:thin:@localhost:1521:XE";
    DefaultTableModel model = new DefaultTableModel(
    new Object [][] {

    },
    new String [] {
        "No.", "Description", "Date", "Debit", "Credit"
    });

    JTable Model = new JTable(model);

    String A_NO = "", A_DESCRIPT = "", A_DATE = "", A_DEBIT = "", A_CREDIT = "";
    java.sql.Date aDate;
    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
    Calendar cal = Calendar.getInstance();

    /** Creates new form ACCOUNT_RECORD */
    public ACCOUNT_RECORD() {
        initComponents();
        this.setLocationRelativeTo(null);
        for (int i = 0; i<50; i++)
        A_yearComboBox.insertItemAt(Integer.toString(Calendar.getInstance().get(Calendar.YEAR) - i), i);
        for (int i = 0; i<50; i++)
        A_yearComboBox1.insertItemAt(Integer.toString(Calendar.getInstance().get(Calendar.YEAR) - i), i);
        A_yearComboBox.setSelectedItem(Integer.toString(Calendar.getInstance().get(Calendar.YEAR)));
        A_yearComboBox1.setSelectedItem(Integer.toString(Calendar.getInstance().get(Calendar.YEAR)));
        everythingRadioButton.setSelected(true);

        if (MAIN_MENU.isAdmin == false)
        A_withdrawButton.setEnabled(false);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        A_parameterbuttonGroup = new javax.swing.ButtonGroup();
        withdrawFrame = new javax.swing.JFrame();
        W_OkayButton = new javax.swing.JButton();
        W_CancelButton = new javax.swing.JButton();
        W_valueLabel = new javax.swing.JLabel();
        W_valueBox = new javax.swing.JTextField();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        everythingRadioButton = new javax.swing.JRadioButton();
        A_balance = new javax.swing.JLabel();
        displaydetailLabel = new javax.swing.JLabel();
        A_monthComboBox1 = new javax.swing.JComboBox();
        mainmenuButton = new javax.swing.JButton();
        A_yearComboBox1 = new javax.swing.JComboBox();
        A_todayRadioButton = new javax.swing.JRadioButton();
        A_thismonthRadioButton = new javax.swing.JRadioButton();
        A_expenditure = new javax.swing.JLabel();
        A_withdrawButton = new javax.swing.JButton();
        A_yearComboBox = new javax.swing.JComboBox();
        A_monthComboBox = new javax.swing.JComboBox();
        A_specificdateRadioButton = new javax.swing.JRadioButton();
        A_dayComboBox1 = new javax.swing.JComboBox();
        A_revenueLabel = new javax.swing.JLabel();
        accountingScrollPane = new javax.swing.JScrollPane();
        accountingTable = new javax.swing.JTable();
        A_revenue = new javax.swing.JLabel();
        A_balanceLabel = new javax.swing.JLabel();
        summaryLabel = new javax.swing.JLabel();
        backButton = new javax.swing.JButton();
        A_expenditureLabel = new javax.swing.JLabel();
        A_displayButton = new javax.swing.JButton();
        A_specificmonthRadioButton = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();

        withdrawFrame.setMinimumSize(new java.awt.Dimension(580, 220));

        W_OkayButton.setText("Ok");
        W_OkayButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                W_OkayButtonActionPerformed(evt);
            }
        });

        W_CancelButton.setText("Cancel");
        W_CancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                W_CancelButtonActionPerformed(evt);
            }
        });

        W_valueLabel.setText("Insert the value you wish to withdraw:          RM");

        javax.swing.GroupLayout withdrawFrameLayout = new javax.swing.GroupLayout(withdrawFrame.getContentPane());
        withdrawFrame.getContentPane().setLayout(withdrawFrameLayout);
        withdrawFrameLayout.setHorizontalGroup(
            withdrawFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(withdrawFrameLayout.createSequentialGroup()
                .addGap(65, 65, 65)
                .addComponent(W_valueLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(withdrawFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(withdrawFrameLayout.createSequentialGroup()
                        .addComponent(W_OkayButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(W_CancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(W_valueBox, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(75, Short.MAX_VALUE))
        );
        withdrawFrameLayout.setVerticalGroup(
            withdrawFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(withdrawFrameLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(withdrawFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(W_valueLabel)
                    .addComponent(W_valueBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(37, 37, 37)
                .addGroup(withdrawFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(W_OkayButton)
                    .addComponent(W_CancelButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(900, 500));
        setResizable(false);

        A_parameterbuttonGroup.add(everythingRadioButton);
        everythingRadioButton.setText("Everything");
        everythingRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                everythingRadioButtonActionPerformed(evt);
            }
        });
        everythingRadioButton.setBounds(40, 50, 130, 30);
        jLayeredPane1.add(everythingRadioButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_balance.setText("RM 0.00");
        A_balance.setBounds(780, 270, 80, 30);
        jLayeredPane1.add(A_balance, javax.swing.JLayeredPane.DEFAULT_LAYER);

        displaydetailLabel.setText("Display accounting details for:");
        displaydetailLabel.setBounds(40, 10, 270, 20);
        jLayeredPane1.add(displaydetailLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_monthComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }));
        A_monthComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                A_monthComboBox1ActionPerformed(evt);
            }
        });
        A_monthComboBox1.setBounds(260, 130, 80, 30);
        jLayeredPane1.add(A_monthComboBox1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        mainmenuButton.setText("Main Menu");
        mainmenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mainmenuButtonActionPerformed(evt);
            }
        });
        mainmenuButton.setBounds(680, 440, 160, 40);
        jLayeredPane1.add(mainmenuButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_yearComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                A_yearComboBox1ActionPerformed(evt);
            }
        });
        A_yearComboBox1.setBounds(350, 130, 70, 30);
        jLayeredPane1.add(A_yearComboBox1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_parameterbuttonGroup.add(A_todayRadioButton);
        A_todayRadioButton.setText("Today");
        A_todayRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                A_todayRadioButtonActionPerformed(evt);
            }
        });
        A_todayRadioButton.setBounds(40, 80, 130, 30);
        jLayeredPane1.add(A_todayRadioButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_parameterbuttonGroup.add(A_thismonthRadioButton);
        A_thismonthRadioButton.setText("This month");
        A_thismonthRadioButton.setBounds(40, 110, 130, 30);
        jLayeredPane1.add(A_thismonthRadioButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_expenditure.setText("RM 0.00");
        A_expenditure.setBounds(780, 300, 80, 20);
        jLayeredPane1.add(A_expenditure, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_withdrawButton.setText("Make withdrawal");
        A_withdrawButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                A_withdrawButtonActionPerformed(evt);
            }
        });
        A_withdrawButton.setBounds(680, 340, 160, 40);
        jLayeredPane1.add(A_withdrawButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_yearComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                A_yearComboBoxActionPerformed(evt);
            }
        });
        A_yearComboBox.setBounds(350, 170, 70, 30);
        jLayeredPane1.add(A_yearComboBox, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_monthComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }));
        A_monthComboBox.setBounds(260, 170, 80, 30);
        jLayeredPane1.add(A_monthComboBox, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_parameterbuttonGroup.add(A_specificdateRadioButton);
        A_specificdateRadioButton.setText("Specific date");
        A_specificdateRadioButton.setBounds(40, 170, 130, 30);
        jLayeredPane1.add(A_specificdateRadioButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_dayComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        A_dayComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                A_dayComboBox1ActionPerformed(evt);
            }
        });
        A_dayComboBox1.setBounds(190, 170, 60, 30);
        jLayeredPane1.add(A_dayComboBox1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_revenueLabel.setText("Revenue");
        A_revenueLabel.setBounds(680, 270, 90, 30);
        jLayeredPane1.add(A_revenueLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        accountingTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "No.", "Description", "Date", "Debit", "Credit"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        accountingTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        accountingTable.setAutoscrolls(false);

        accountingTable.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        accountingTable.setEnabled(false);

        accountingTable.setRowSelectionAllowed(false);
        accountingTable.getTableHeader().setReorderingAllowed(false);
        accountingScrollPane.setViewportView(accountingTable);
        accountingTable.getColumnModel().getColumn(0).setResizable(false);
        accountingTable.getColumnModel().getColumn(0).setPreferredWidth(40);
        accountingTable.getColumnModel().getColumn(1).setResizable(false);
        accountingTable.getColumnModel().getColumn(1).setPreferredWidth(200);
        accountingTable.getColumnModel().getColumn(2).setResizable(false);
        accountingTable.getColumnModel().getColumn(2).setPreferredWidth(75);
        accountingTable.getColumnModel().getColumn(3).setResizable(false);
        accountingTable.getColumnModel().getColumn(3).setPreferredWidth(75);
        accountingTable.getColumnModel().getColumn(4).setResizable(false);
        accountingTable.getColumnModel().getColumn(4).setPreferredWidth(75);

        accountingScrollPane.setBounds(30, 207, 600, 270);
        jLayeredPane1.add(accountingScrollPane, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_revenue.setText("RM 0.00");
        A_revenue.setBounds(780, 250, 80, 20);
        jLayeredPane1.add(A_revenue, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_balanceLabel.setText("Balance");
        A_balanceLabel.setBounds(680, 250, 90, 20);
        jLayeredPane1.add(A_balanceLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        summaryLabel.setText("Accounting summary:");
        summaryLabel.setBounds(680, 210, 180, 30);
        jLayeredPane1.add(summaryLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        backButton.setText("Back");
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });
        backButton.setBounds(680, 390, 160, 40);
        jLayeredPane1.add(backButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_expenditureLabel.setText("Expenditure");
        A_expenditureLabel.setBounds(680, 300, 90, 20);
        jLayeredPane1.add(A_expenditureLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_displayButton.setText("Display");
        A_displayButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                A_displayButtonActionPerformed(evt);
            }
        });
        A_displayButton.setBounds(550, 153, 100, 40);
        jLayeredPane1.add(A_displayButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        A_parameterbuttonGroup.add(A_specificmonthRadioButton);
        A_specificmonthRadioButton.setText("Specific month");
        A_specificmonthRadioButton.setBounds(40, 140, 130, 30);
        jLayeredPane1.add(A_specificmonthRadioButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGE_REPOSITORY/Background3 copy.jpg"))); // NOI18N
        jLabel1.setText("jLabel1");
        jLabel1.setBounds(0, 0, 900, 500);
        jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 900, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                        

    private void A_todayRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        // TODO add your handling code here:
}                                                  

    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
    this.setVisible(false);
    new ADMIN_CONSOLE().setVisible(true);// TODO add your handling code here:
}                                          

    private void A_dayComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // TODO add your handling code here:
}                                              

    DecimalFormat df = new DecimalFormat("#0.00");

    private void A_displayButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                
      
        
        try {
            DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
            Connection con;
            con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","javaproject","javaproject");


            switch(Calendar.getInstance().get(Calendar.MONTH)){
                 case 0:
                     A_DATE=Calendar.getInstance().get(Calendar.DATE)+"-JAN-"+Calendar.getInstance().get(Calendar.YEAR);
                     break;
                 case 1:
                     A_DATE=Calendar.getInstance().get(Calendar.DATE)+"-FEB-"+Calendar.getInstance().get(Calendar.YEAR);
                     break;
                 case 2:
                     A_DATE=Calendar.getInstance().get(Calendar.DATE)+"-MAR-"+Calendar.getInstance().get(Calendar.YEAR);
                     break;
                 case 3:
                     A_DATE=Calendar.getInstance().get(Calendar.DATE)+"-APR-"+Calendar.getInstance().get(Calendar.YEAR);
                     break;
                 case 4:
                     A_DATE=Calendar.getInstance().get(Calendar.DATE)+"-MAY-"+Calendar.getInstance().get(Calendar.YEAR);
                     break;
                 case 5:
                     A_DATE=Calendar.getInstance().get(Calendar.DATE)+"-JUN-"+Calendar.getInstance().get(Calendar.YEAR);
                     break;
                 case 6:
                     A_DATE=Calendar.getInstance().get(Calendar.DATE)+"-JUL-"+Calendar.getInstance().get(Calendar.YEAR);
                     break;
                 case 7:
                     A_DATE=Calendar.getInstance().get(Calendar.DATE)+"-AUG-"+Calendar.getInstance().get(Calendar.YEAR);
                     break;
                 case 8:
                     A_DATE=Calendar.getInstance().get(Calendar.DATE)+"-SEP-"+Calendar.getInstance().get(Calendar.YEAR);
                     break;
                 case 9:
                     A_DATE=Calendar.getInstance().get(Calendar.DATE)+"-OCT-"+Calendar.getInstance().get(Calendar.YEAR);
                     break;
                 case 10:
                     A_DATE=Calendar.getInstance().get(Calendar.DATE)+"-NOV-"+Calendar.getInstance().get(Calendar.YEAR);
                     break;
                 case 11:
                     A_DATE=Calendar.getInstance().get(Calendar.DATE)+"-DEC-"+Calendar.getInstance().get(Calendar.YEAR);
                     break;
             }
            
        if (everythingRadioButton.isSelected())
        {
        stmt = con.prepareStatement("Select * from ACCOUNTING");
        rset = stmt.executeQuery();
        }
        else if (A_todayRadioButton.isSelected())
        {
        stmt = con.prepareStatement("Select * from ACCOUNTING WHERE EVENT_DATE = ?");
        stmt.setString(1, A_DATE);
        rset = stmt.executeQuery();
        }
        else if (A_thismonthRadioButton.isSelected())
        {
        stmt = con.prepareStatement("Select * from ACCOUNTING WHERE TO_CHAR(EVENT_DATE, 'MM') = ? AND TO_CHAR(EVENT_DATE, 'YYYY') = ?");
        stmt.setString(1, Integer.toString(Calendar.getInstance().get(Calendar.MONTH)+1));
        stmt.setString(2, Integer.toString(Calendar.getInstance().get(Calendar.YEAR)));
        rset = stmt.executeQuery();
        }
        else if (A_specificmonthRadioButton.isSelected())
        {
        stmt = con.prepareStatement("Select * from ACCOUNTING WHERE TO_CHAR(EVENT_DATE, 'MM') = ? AND TO_CHAR(EVENT_DATE, 'YYYY') = ?");
        stmt.setString(1, Integer.toString(A_monthComboBox.getSelectedIndex()+1));
        stmt.setString(2, A_yearComboBox.getSelectedItem().toString());
        rset = stmt.executeQuery();
        }
        else if (A_specificdateRadioButton.isSelected())
        {
        stmt = con.prepareStatement("Select * from ACCOUNTING WHERE TO_CHAR(EVENT_DATE, 'DD') = ? AND TO_CHAR(EVENT_DATE, 'MM') = ? AND TO_CHAR(EVENT_DATE, 'YYYY') = ?");
        stmt.setString(1, A_dayComboBox1.getSelectedItem().toString());
        stmt.setString(2, Integer.toString(A_monthComboBox1.getSelectedIndex()+1));
        stmt.setString(3, A_yearComboBox1.getSelectedItem().toString());
        rset = stmt.executeQuery();
        }

        

        for (int j = model.getRowCount()-1; j>=0; j--)
        model.removeRow(j);
        int i = 0;

        while(rset.next())
        {

        A_NO = rset.getString(1);
        aDate = rset.getDate(2);
        A_DESCRIPT = rset.getString(3);
        A_DEBIT = rset.getString(4);
        A_CREDIT = rset.getString(5);

        if (A_DEBIT != null)
        A_DEBIT = df.format(Double.parseDouble(A_DEBIT));

        if (A_CREDIT  != null)
        A_CREDIT = df.format(Double.parseDouble(A_CREDIT));

        model.insertRow(i,new Object[]{i+1,A_DESCRIPT,aDate,A_DEBIT,A_CREDIT});

        i++;
        }
        stmt.close();
        accountingTable.setModel(model);
        accountingTable.getColumnModel().getColumn(0).setResizable(false);
        accountingTable.getColumnModel().getColumn(0).setPreferredWidth(40);
        accountingTable.getColumnModel().getColumn(1).setResizable(false);
        accountingTable.getColumnModel().getColumn(1).setPreferredWidth(200);
        accountingTable.getColumnModel().getColumn(2).setResizable(false);
        accountingTable.getColumnModel().getColumn(2).setPreferredWidth(75);
        accountingTable.getColumnModel().getColumn(3).setResizable(false);
        accountingTable.getColumnModel().getColumn(3).setPreferredWidth(75);
        accountingTable.getColumnModel().getColumn(4).setResizable(false);
        accountingTable.getColumnModel().getColumn(4).setPreferredWidth(75);
        revenue = 0;
        expenditure = 0;
        for (int j = 0; j<accountingTable.getRowCount(); j++){
        if (accountingTable.getValueAt(j, 3)!=null)
        revenue += Double.parseDouble(accountingTable.getValueAt(j, 3).toString());
        if (accountingTable.getValueAt(j, 4)!=null)
        expenditure += Double.parseDouble(accountingTable.getValueAt(j, 4).toString());
        }
        revenue = Double.parseDouble(df.format(revenue));
        expenditure = Double.parseDouble(df.format(expenditure));
        A_balance.setText("RM "+(revenue-expenditure));
        A_revenue.setText("RM "+revenue);
        A_expenditure.setText("RM "+expenditure);
        }
        catch (Exception e) {
        JOptionPane.showMessageDialog
        (null, "Failed to Retreive Data!", "ERROR", JOptionPane.ERROR_MESSAGE);
        }


    }                                               

    private void DateAdjuster(){
    int cyear = Integer.parseInt( A_yearComboBox1.getSelectedItem().toString());

    if (cyear%4 == 0)
    {
    if (A_monthComboBox1.getSelectedItem()=="Feb")
    {
    A_dayComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29"}));
    A_dayComboBox1.setSelectedItem("1");
    } //febselected
    } //cyear%4 == 0
    else
    {
    if (A_monthComboBox1.getSelectedItem()=="Feb")
    {
    A_dayComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28"}));
    A_dayComboBox1.setSelectedItem("1");
    } //febselected
    } //cyear%4 != 0

    if (A_monthComboBox1.getSelectedItem()=="Jan" || A_monthComboBox1.getSelectedItem()=="Mar" || A_monthComboBox1.getSelectedItem()=="May" || A_monthComboBox1.getSelectedItem()=="Jul" || A_monthComboBox1.getSelectedItem()=="Aug" || A_monthComboBox1.getSelectedItem()=="Oct" || A_monthComboBox1.getSelectedItem()=="Dec")
    {
    A_dayComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}));
    A_dayComboBox1.setSelectedItem("1");
    }
    else if (A_monthComboBox1.getSelectedItem()=="Apr" || A_monthComboBox1.getSelectedItem()=="Jun" || A_monthComboBox1.getSelectedItem()=="Sep" || A_monthComboBox1.getSelectedItem()=="Nov")
    {
    A_dayComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"}));
    A_dayComboBox1.setSelectedItem("1");
    }

    } //end DateAdjuster

    private void A_yearComboBoxActionPerformed(java.awt.event.ActionEvent evt) {                                               

    }                                              

    private void A_monthComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                                 
    DateAdjuster();
    }                                                

    private void A_yearComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                                
    DateAdjuster();
    }                                               

    private void everythingRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                      

    }                                                     

    private void mainmenuButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
    new MAIN_MENU().setVisible(true);
    this.setVisible(false);// TODO add your handling code here:
    }                                              

    private void A_withdrawButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                 
    withdrawFrame.setVisible(true);
    this.setEnabled(false);
    }                                                

    double withdraw;

    private void W_OkayButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             

    if (W_valueBox.getText() == null || W_valueBox.getText() == "")
    JOptionPane.showMessageDialog(null, "Please place a proper input.");    
    else {
      try
            {
                DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","javaproject","javaproject");;

//      --------------------------------------------------------------------------------------------------


                withdraw = Double.parseDouble(W_valueBox.getText());

                stmt = con.prepareStatement("INSERT INTO ACCOUNTING(EVENT_ENTRY_NO, EVENT_DATE, EVENT_DESCRIPT, EVENT_DEBIT, EVENT_CREDIT) VALUES(ACCOUNTING_SEQ.nextval,'"+ dateFormat.format(cal.getTime()) + "','Withdrawal from " + MAIN_MENU.staffOnDuty + "', null,"
                		                  + withdraw + ")");

//      --------------------------------------------------------------------------------------------------

            stmt.executeUpdate();
            stmt.close();

            System.out.println("Your withdrawal is successful.");
            JOptionPane.showMessageDialog(null, "Withdrawal Successful.", "System Message", JOptionPane.INFORMATION_MESSAGE);
            withdrawFrame.setVisible(false);
            this.setEnabled(true);
            this.setVisible(true);

            }//end try
            catch (Exception e)
            {
                JOptionPane.showMessageDialog(null, "Error, connection unestablished or poor entry.");}
        }
    
    }                                            

    private void W_CancelButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
    withdrawFrame.setVisible(false);
    this.setEnabled(true);
    this.setVisible(true);
    }                                              

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ACCOUNT_RECORD().setVisible(true);
            }
        });
    }

      private void connect() throws SQLException
    {
        DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
        System.out.println("Driver Loaded");
        con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","javaproject","javaproject");
        System.out.println("Database Connected");

    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel A_balance;
    private javax.swing.JLabel A_balanceLabel;
    private javax.swing.JComboBox A_dayComboBox1;
    private javax.swing.JButton A_displayButton;
    private javax.swing.JLabel A_expenditure;
    private javax.swing.JLabel A_expenditureLabel;
    private javax.swing.JComboBox A_monthComboBox;
    private javax.swing.JComboBox A_monthComboBox1;
    private javax.swing.ButtonGroup A_parameterbuttonGroup;
    private javax.swing.JLabel A_revenue;
    private javax.swing.JLabel A_revenueLabel;
    private javax.swing.JRadioButton A_specificdateRadioButton;
    private javax.swing.JRadioButton A_specificmonthRadioButton;
    private javax.swing.JRadioButton A_thismonthRadioButton;
    private javax.swing.JRadioButton A_todayRadioButton;
    private javax.swing.JButton A_withdrawButton;
    private javax.swing.JComboBox A_yearComboBox;
    private javax.swing.JComboBox A_yearComboBox1;
    private javax.swing.JButton W_CancelButton;
    private javax.swing.JButton W_OkayButton;
    private javax.swing.JTextField W_valueBox;
    private javax.swing.JLabel W_valueLabel;
    private javax.swing.JScrollPane accountingScrollPane;
    private javax.swing.JTable accountingTable;
    private javax.swing.JButton backButton;
    private javax.swing.JLabel displaydetailLabel;
    private javax.swing.JRadioButton everythingRadioButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JButton mainmenuButton;
    private javax.swing.JLabel summaryLabel;
    private javax.swing.JFrame withdrawFrame;
    // End of variables declaration                   

}
